﻿
-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Ivy_GetAllUsersBySocietyKey')
	BEGIN
		DROP  Procedure  Ivy_GetAllUsersBySocietyKey
	END

GO

CREATE PROCEDURE [Ivy_GetAllUsersBySocietyKey]
-- =============================================
-- Author:		<Sagar sk>
-- Create date: <06-12-2014>
-- Description:	<Ivy_GetAllUsersBySocietyKey>
-- =============================================
-- Add the parameters for the stored procedure here
	(
				@UserSocietyKey int = 0
				
	)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	SELECT DISTINCT   
			[User].UserKey, 
			[User].UserLoginID, 
			[User].UserFirstName, 
			[User].UserLastName, 
			[UserProfile].UserFullName, 
			[UserProfile].UserSex, 
			[UserProfile].UserDateOfBirth, 
			[UserProfile].UserContactNumber, 
			[UserProfile].UserContactAddress, 
			[UserRole].UserSocietyKey
	FROM        
			[User] LEFT OUTER JOIN [UserRole] ON 
			[User].UserKey = [UserRole].UserKey LEFT OUTER JOIN
            [UserProfile] ON [User].UserKey = [UserProfile].UserKey
	WHERE     
			(UserRole.UserSocietyKey = @UserSocietyKey);
END
GO
